from django.db import models
from django.contrib.auth.models import User


class BlogItem(models.Model):
    """
    微博内容
    """
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
    # 微博内容
    content = models.CharField(max_length=200)
    # 昵称
    nickname = models.CharField(max_length=20)
    # 头像
    portrait = models.CharField(max_length=20)

    add_time = models.DateTimeField(auto_now=True)

    # 是否删除。默认为0，1为已删除
    is_del = models.SmallIntegerField(default=0)
    ip = models.CharField(max_length=200, default="")

    def __str__(self):
        return self.content


class LoginLog(models.Model):
    """
    暂用的登录记录
    """
    token = models.CharField(max_length=100)
    username = models.CharField(max_length=100)

    # 校验是否是正确的调用者.使用ip与浏览器信信息结合加密
    validate_code = models.CharField(max_length=2000)
    add_time = models.DateTimeField(auto_now=True)
    # 0为默认未作废，1为有效
    is_del = models.SmallIntegerField(default=0)
